//package com.geek.bams.client;
//
//
//import com.geek.bams.entity.*;
//
//import javax.swing.*;
//import java.awt.*;
//import java.awt.event.ActionEvent;
//import java.io.IOException;
//
//public class BusinessPanel extends JPanel {
//    private ATMClient atm;
//
//    public BusinessPanel( ATMClient atm) {
//        this.atm = atm;
//        initComponents();
//    }
//
//    //初始化界面
//    public void initBusiness(){
//        //使用 atm.acc 共有账户资源 进行初始化数据
//        idText.setText(atm.account.getId()+"");
//        nameLabelText.setText(atm.account.getName());
//        balanceLabelText.setText(atm.account.getBalance()+"");
//        moneyTextField.setText(0.0+"");
//
//        //透支额度
//        if(atm.account instanceof CreditAccount){
//            ceilingLabelText.setText(((CreditAccount) atm.account).getCeiling()+"");
//        }else{
//            ceilingLabelText.setText("该账户不支持透支操作");
//        }
//
//        //贷款额度
//        if(atm.account instanceof LoanSavingAccount){
//            loanLabelText.setText(((LoanSavingAccount) atm.account).getLoanAmount()+"");
//        }else if(atm.account instanceof LoanCreditAccount){
//            loanLabelText.setText(((LoanCreditAccount) atm.account).getLoanAmount()+"");
//        }else{
//            loanLabelText.setText("该账户不支持贷款操作");
//        }
//
//        //下拉菜单  不同账户类型，展示不同的可操作的项
//        if(atm.account instanceof LoanSavingAccount){
//            comboBox.setModel(new DefaultComboBoxModel<>(new String[] {"存款","取款","转账","贷款","还贷"}));
//        }else if(atm.account instanceof LoanCreditAccount){
//            comboBox.setModel(new DefaultComboBoxModel<>(new String[] {"存款","取款","转账","修改透支额度","贷款","还贷"}));
//        }else if(atm.account instanceof CreditAccount){
//            comboBox.setModel(new DefaultComboBoxModel<>(new String[] {"存款","取款","转账","修改透支额度"}));
//        }else if(atm.account instanceof SavingAccount){
//            comboBox.setModel(new DefaultComboBoxModel<>(new String[] {"存款","取款","转账"}));
//        }
//    }
//    //点击提交数据，进行业务处理
//    //提交业务操作  执行Bank业务 -> 刷新页面
//    private void submit(ActionEvent e) {
//        Long id = Long.valueOf(idText.getText());
//        String moneyText = moneyTextField.getText();
//        String select = comboBox.getSelectedItem().toString();
//
//        Account acc = null;
//        if (moneyText != null && !moneyText.equals("")) {
//            double money = Double.parseDouble(moneyText);
//            if (money > 0.0) {
//                switch (select) {
//                    case "存款":
//                       /* //未添加网络编程  begin
//                        try {
//                            acc = atm.bank.deposit(id, money);
//                        } catch (Exception ex) {
//                            JOptionPane.showMessageDialog(null, ex.getMessage());
//                            moneyTextField.setText("0.0");
//                        }
//                        break;
//                        //未添加网络编程 end*/
//
//                        //===============添加网络编程  begin
//                        //1.发送指令
//                        atm.pw.println("deposit#"+id+"#"+money);
//                        atm.pw.flush();
//
//                        //4.读结果
//                        try {
//                            Object o = atm.ois.readObject();
//                            if(o instanceof Account){
//                                acc = (Account) o;
//                            }else if(o instanceof String){
//                                JOptionPane.showMessageDialog(this , o);
//                                moneyTextField.setText("0.0");
//                            }
//                        } catch (IOException ex) {
//                            JOptionPane.showMessageDialog(this , "服务器已关闭");
//                            System.exit(0);
//                        } catch (ClassNotFoundException ex) {
//                            throw new RuntimeException(ex);
//                        }
//                        break;
//                        //===============添加网络编程  end
//                    case "取款":
//                        String pwd = JOptionPane.showInputDialog(null, "请输入您的密码：");
//                       /* //未添加网络编程 end
//                        try {
//                            acc = atm.bank.withdraw(id, pwd, money);
//                        } catch (Exception ex) {
//                            JOptionPane.showMessageDialog(null, ex.getMessage());
//                            moneyTextField.setText("0.0");
//                        }
//                        break;
//                        //未添加网络编程 end*/
//
//                        //===============添加网络编程  begin
//                        //1.发送指令
//                        atm.pw.println("withdraw#"+id+"#"+pwd+"#"+money);
//                        atm.pw.flush();
//
//                        //4.读结果
//                        try {
//                            Object o = atm.ois.readObject();
//                            if(o instanceof Account){
//                                acc = (Account) o;
//                            }else if(o instanceof String){
//                                JOptionPane.showMessageDialog(this , o);
//                                moneyTextField.setText("0.0");
//                            }
//                        } catch (IOException ex) {
//                            JOptionPane.showMessageDialog(this , "服务器已关闭");
//                            System.exit(0);
//                        } catch (ClassNotFoundException ex) {
//                            throw new RuntimeException(ex);
//                        }
//                        break;
//                        //===============添加网络编程  end
//
//                    case "转账":
//                        String toIdStr = JOptionPane.showInputDialog(null, "请输入转入账户：");
//                        String password = JOptionPane.showInputDialog(null, "请输入您的密码：");
//                        if (toIdStr.matches("\\d+")) {
//                            /*//未添加网络编程  begin
//                            Long to = Long.valueOf(toIdStr);
//                            try {
//                                boolean flag = atm.bank.transfer(id, password, to, money);
//                                if (flag) {
//                                    acc = atm.bank.login(id, password);
//                                }
//                            } catch (Exception ex) {
//                                JOptionPane.showMessageDialog(null, ex.getMessage());
//                                moneyTextField.setText("0.0");
//                            }
//                            //未添加网络编程 end*/
//
//                            //===============添加网络编程  begin
//                            //1.发送指令
//                            atm.pw.println("transfer#"+id+"#"+password+"#"+toIdStr+"#"+money);
//                            atm.pw.flush();
//
//                            //4.读结果
//                            try {
//                                Object o = atm.ois.readObject();
//                                if(o instanceof Account){
//                                    acc = (Account) o;
//                                }else if(o instanceof String){
//                                    JOptionPane.showMessageDialog(this , o);
//                                    moneyTextField.setText("0.0");
//                                }
//                            } catch (IOException ex) {
//                                JOptionPane.showMessageDialog(this , "服务器已关闭");
//                                System.exit(0);
//                            } catch (ClassNotFoundException ex) {
//                                throw new RuntimeException(ex);
//                            }
//                            //===============添加网络编程  end
//                        } else {
//                            JOptionPane.showMessageDialog(null, "转入账户不合法");
//                        }
//                        break;
//                    case "修改透支额度":
//                        password = JOptionPane.showInputDialog(null, "请输入您的密码：");
//                        /*//未添加网络编程  begin
//                        try {
//                            acc = atm.bank.updateCeiling(id, password, money);
//                        } catch (Exception ex) {
//                            JOptionPane.showMessageDialog(null, ex.getMessage());
//                            moneyTextField.setText("0.0");
//                        }
//                        break;
//                        //未添加网络编程 end*/
//
//                        //===============添加网络编程  begin
//                        //1.发送指令
//                        atm.pw.println("updateCeiling#"+id+"#"+password+"#"+money);
//                        atm.pw.flush();
//
//                        //4.读结果
//                        try {
//                            Object o = atm.ois.readObject();
//                            if(o instanceof Account){
//                                acc = (Account) o;
//                            }else if(o instanceof String){
//                                JOptionPane.showMessageDialog(this , o);
//                                moneyTextField.setText("0.0");
//                            }
//                        } catch (IOException ex) {
//                            JOptionPane.showMessageDialog(this , "服务器已关闭");
//                            System.exit(0);
//                        } catch (ClassNotFoundException ex) {
//                            throw new RuntimeException(ex);
//                        }
//                        break;
//                        //===============添加网络编程  end
//
//                    case "贷款":
//                       /* //未添加网络编程  begin
//                        try {
//                            acc = atm.bank.requestLoan(id, money);
//                        } catch (Exception ex) {
//                            JOptionPane.showMessageDialog(null, ex.getMessage());
//                            moneyTextField.setText("0.0");
//                        }
//                        break;
//                       //未添加网络编程 end*/
//
//                        //===============添加网络编程  begin
//                        //1.发送指令
//                        atm.pw.println("requestLoan#"+id+"#"+money);
//                        atm.pw.flush();
//
//                        //4.读结果
//                        try {
//                            Object o = atm.ois.readObject();
//                            if(o instanceof Account){
//                                acc = (Account) o;
//                            }else if(o instanceof String){
//                                JOptionPane.showMessageDialog(this , o);
//                                moneyTextField.setText("0.0");
//                            }
//                        } catch (IOException ex) {
//                            JOptionPane.showMessageDialog(this , "服务器已关闭");
//                            System.exit(0);
//                        } catch (ClassNotFoundException ex) {
//                            throw new RuntimeException(ex);
//                        }
//                        break;
//                        //===============添加网络编程  end
//
//                    case "还贷":
//                        /*//未添加网络编程  begin
//                        try {
//                            acc = atm.bank.payLoan(id, money);
//                        } catch (Exception ex) {
//                            JOptionPane.showMessageDialog(null, ex.getMessage());
//                            moneyTextField.setText("0.0");
//                        }
//                        break;
//                        //未添加网络编程 end*/
//
//                        //===============添加网络编程  begin
//                        //1.发送指令
//                        atm.pw.println("payLoan#"+id+"#"+money);
//                        atm.pw.flush();
//
//                        //4.读结果
//                        try {
//                            Object o = atm.ois.readObject();
//                            if(o instanceof Account){
//                                acc = (Account) o;
//                            }else if(o instanceof String){
//                                JOptionPane.showMessageDialog(this , o);
//                                moneyTextField.setText("0.0");
//                            }
//                        } catch (IOException ex) {
//                            JOptionPane.showMessageDialog(this , "服务器已关闭");
//                            System.exit(0);
//                        } catch (ClassNotFoundException ex) {
//                            throw new RuntimeException(ex);
//                        }
//                        //===============添加网络编程  end
//                        break;
//                }
//
//                // 刷新页面：初始化业务界面
//                if (acc != null) {
//                    atm.account = acc;
//                    initBusiness();
//                }
//            } else {
//                JOptionPane.showMessageDialog(null, "操作金额必须>0.0！");
//            }
//        } else {
//            JOptionPane.showMessageDialog(null, "金额必须输入！");
//        }
//    }
//
//    //点击返回，返回主界面
//    private void back(ActionEvent e) {
//        // TODO add your code here
//        //获取当前LoginPanel的父窗口（ATMClient），的布局方式，即卡片式布局
//        CardLayout cardLayout = (CardLayout)this.getParent().getLayout();
//        //指定跳转至主界面
//        cardLayout.show(this.getParent() , "mainPanel");
//        clear();
//    }
//    //清空业务界面
//    private void clear(){
//        idText.setText("");
//        nameLabelText.setText("");
//        balanceLabelText.setText("");
//        ceilingLabelText.setText("");
//        loanLabelText.setText("");
//        comboBox.setSelectedIndex(0);
//        moneyTextField.setText(0.0+"");
//    }
//    private void initComponents() {
//        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents  @formatter:off
//        label1 = new JLabel();
//        label2 = new JLabel();
//        label3 = new JLabel();
//        label4 = new JLabel();
//        label5 = new JLabel();
//        comboBox = new JComboBox<>();
//        moneyTextField = new JTextField();
//        submitButton = new JButton();
//        backButton = new JButton();
//        label6 = new JLabel();
//        label7 = new JLabel();
//        idLabelText = new JLabel();
//        nameLabelText = new JLabel();
//        balanceLabelText = new JLabel();
//        ceilingLabelText = new JLabel();
//        loanLabelText = new JLabel();
//        label8 = new JLabel();
//        idText = new JLabel();
//
//        //======== this ========
//        setLayout(null);
//
//        //---- label1 ----
//        label1.setText("\u8d26\u6237\uff1a");
//        label1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 16));
//        add(label1);
//        label1.setBounds(80, 100, 90, 30);
//
//        //---- label2 ----
//        label2.setText("\u59d3\u540d\uff1a");
//        label2.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 16));
//        add(label2);
//        label2.setBounds(80, 160, 90, 30);
//
//        //---- label3 ----
//        label3.setText("\u4f59\u989d\uff1a");
//        label3.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 16));
//        add(label3);
//        label3.setBounds(80, 220, 90, 30);
//
//        //---- label4 ----
//        label4.setText("\u4fe1\u7528\u989d\u5ea6\uff1a");
//        label4.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 16));
//        add(label4);
//        label4.setBounds(80, 280, 90, 30);
//
//        //---- label5 ----
//        label5.setText("\u8d37\u6b3e\u989d\u5ea6\uff1a");
//        label5.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 16));
//        add(label5);
//        label5.setBounds(80, 340, 90, 30);
//
//        //---- comboBox ----
//        comboBox.setModel(new DefaultComboBoxModel<>(new String[] {
//            "\u5b58\u6b3e",
//            "\u53d6\u6b3e",
//            "\u8f6c\u8d26",
//            "\u4fee\u6539\u900f\u652f\u989d\u5ea6",
//            "\u8d37\u6b3e",
//            "\u8fd8\u8d37"
//        }));
//        add(comboBox);
//        comboBox.setBounds(65, 415, 130, 35);
//
//        //---- moneyTextField ----
//        moneyTextField.setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR));
//        moneyTextField.setText("0.0");
//        add(moneyTextField);
//        moneyTextField.setBounds(260, 415, 145, 35);
//
//        //---- submitButton ----
//        submitButton.setText("\u63d0\u4ea4");
//        submitButton.addActionListener(e -> submit(e));
//        add(submitButton);
//        submitButton.setBounds(75, 505, 80, 30);
//
//        //---- backButton ----
//        backButton.setText("\u8fd4\u56de");
//        backButton.addActionListener(e -> back(e));
//        add(backButton);
//        backButton.setBounds(305, 505, 80, 30);
//        add(label6);
//        label6.setBounds(145, 25, 105, label6.getPreferredSize().height);
//        add(label7);
//        label7.setBounds(150, 30, 100, label7.getPreferredSize().height);
//        add(idLabelText);
//        idLabelText.setBounds(115, 65, 185, idLabelText.getPreferredSize().height);
//
//        //---- nameLabelText ----
//        nameLabelText.setText(" ");
//        add(nameLabelText);
//        nameLabelText.setBounds(240, 160, 160, 35);
//
//        //---- balanceLabelText ----
//        balanceLabelText.setText(" ");
//        add(balanceLabelText);
//        balanceLabelText.setBounds(240, 220, 160, 35);
//
//        //---- ceilingLabelText ----
//        ceilingLabelText.setText(" ");
//        add(ceilingLabelText);
//        ceilingLabelText.setBounds(240, 280, 160, 35);
//
//        //---- loanLabelText ----
//        loanLabelText.setText(" ");
//        add(loanLabelText);
//        loanLabelText.setBounds(240, 340, 160, 35);
//
//        //---- label8 ----
//        label8.setText("\u4e1a\u52a1\u9875\u9762");
//        label8.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 24));
//        label8.setHorizontalAlignment(SwingConstants.CENTER);
//        add(label8);
//        label8.setBounds(195, 25, 100, 40);
//
//        //---- idText ----
//        idText.setText(" ");
//        add(idText);
//        idText.setBounds(240, 100, 160, 35);
//
//        setPreferredSize(new Dimension(500, 650));
//        // JFormDesigner - End of component initialization  //GEN-END:initComponents  @formatter:on
//    }
//
//    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables  @formatter:off
//    private JLabel label1;
//    private JLabel label2;
//    private JLabel label3;
//    private JLabel label4;
//    private JLabel label5;
//    private JComboBox<String> comboBox;
//    private JTextField moneyTextField;
//    private JButton submitButton;
//    private JButton backButton;
//    private JLabel label6;
//    private JLabel label7;
//    private JLabel idLabelText;
//    private JLabel nameLabelText;
//    private JLabel balanceLabelText;
//    private JLabel ceilingLabelText;
//    private JLabel loanLabelText;
//    private JLabel label8;
//    private JLabel idText;
//    // JFormDesigner - End of variables declaration  //GEN-END:variables  @formatter:on
//}


package com.geek.bams.client;


import com.geek.bams.entity.*;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.io.IOException;

public class BusinessPanel extends JPanel {
    private ATMClient atm;
    private Thread refreshThread; // 添加刷新线程

    public BusinessPanel( ATMClient atm) {
        this.atm = atm;
        initComponents();
        startRefreshListener(); // 启动刷新监听器
    }

    //初始化界面
    public void initBusiness(){
        //使用 atm.acc 共有账户资源 进行初始化数据
        idText.setText(atm.account.getId()+"");
        nameLabelText.setText(atm.account.getName());
        balanceLabelText.setText(atm.account.getBalance()+"");
        moneyTextField.setText(0.0+"");

        //透支额度
        if(atm.account instanceof CreditAccount){
            ceilingLabelText.setText(((CreditAccount) atm.account).getCeiling()+"");
        }else{
            ceilingLabelText.setText("该账户不支持透支操作");
        }

        //贷款额度
        if(atm.account instanceof LoanSavingAccount){
            loanLabelText.setText(((LoanSavingAccount) atm.account).getLoanAmount()+"");
        }else if(atm.account instanceof LoanCreditAccount){
            loanLabelText.setText(((LoanCreditAccount) atm.account).getLoanAmount()+"");
        }else{
            loanLabelText.setText("该账户不支持贷款操作");
        }

        //下拉菜单  不同账户类型，展示不同的可操作的项
        if(atm.account instanceof LoanSavingAccount){
            comboBox.setModel(new DefaultComboBoxModel<>(new String[] {"存款","取款","转账","贷款","还贷"}));
        }else if(atm.account instanceof LoanCreditAccount){
            comboBox.setModel(new DefaultComboBoxModel<>(new String[] {"存款","取款","转账","修改透支额度","贷款","还贷"}));
        }else if(atm.account instanceof CreditAccount){
            comboBox.setModel(new DefaultComboBoxModel<>(new String[] {"存款","取款","转账","修改透支额度"}));
        }else if(atm.account instanceof SavingAccount){
            comboBox.setModel(new DefaultComboBoxModel<>(new String[] {"存款","取款","转账"}));
        }
    }
    //点击提交数据，进行业务处理
    //提交业务操作  执行Bank业务 -> 刷新页面
    private void submit(ActionEvent e) {
        Long id = Long.valueOf(idText.getText());
        String moneyText = moneyTextField.getText();
        String select = comboBox.getSelectedItem().toString();

        Account acc = null;
        if (moneyText != null && !moneyText.equals("")) {
            double money = Double.parseDouble(moneyText);
            if (money > 0.0) {
                switch (select) {
                    case "存款":
                       /* //未添加网络编程  begin
                        try {
                            acc = atm.bank.deposit(id, money);
                        } catch (Exception ex) {
                            JOptionPane.showMessageDialog(null, ex.getMessage());
                            moneyTextField.setText("0.0");
                        }
                        break;
                        //未添加网络编程 end*/

                        //===============添加网络编程  begin
                        //1.发送指令
                        atm.pw.println("deposit#"+id+"#"+money);
                        atm.pw.flush();

                        //4.读结果
                        try {
                            Object o = atm.ois.readObject();
                            if(o instanceof Account){
                                acc = (Account) o;
                            }else if(o instanceof String){
                                JOptionPane.showMessageDialog(this , o);
                                moneyTextField.setText("0.0");
                            }
                        } catch (IOException ex) {
                            JOptionPane.showMessageDialog(this , "服务器已关闭");
                            System.exit(0);
                        } catch (ClassNotFoundException ex) {
                            throw new RuntimeException(ex);
                        }
                        break;
                    //===============添加网络编程  end
                    case "取款":
                        String pwd = JOptionPane.showInputDialog(null, "请输入您的密码：");
                       /* //未添加网络编程 end
                        try {
                            acc = atm.bank.withdraw(id, pwd, money);
                        } catch (Exception ex) {
                            JOptionPane.showMessageDialog(null, ex.getMessage());
                            moneyTextField.setText("0.0");
                        }
                        break;
                        //未添加网络编程 end*/

                        //===============添加网络编程  begin
                        //1.发送指令
                        atm.pw.println("withdraw#"+id+"#"+pwd+"#"+money);
                        atm.pw.flush();

                        //4.读结果
                        try {
                            Object o = atm.ois.readObject();
                            if(o instanceof Account){
                                acc = (Account) o;
                            }else if(o instanceof String){
                                JOptionPane.showMessageDialog(this , o);
                                moneyTextField.setText("0.0");
                            }
                        } catch (IOException ex) {
                            JOptionPane.showMessageDialog(this , "服务器已关闭");
                            System.exit(0);
                        } catch (ClassNotFoundException ex) {
                            throw new RuntimeException(ex);
                        }
                        break;
                    //===============添加网络编程  end

                    case "转账":
                        String toIdStr = JOptionPane.showInputDialog(null, "请输入转入账户：");
                        String password = JOptionPane.showInputDialog(null, "请输入您的密码：");
                        if (toIdStr.matches("\\d+")) {
                            /*//未添加网络编程  begin
                            Long to = Long.valueOf(toIdStr);
                            try {
                                boolean flag = atm.bank.transfer(id, password, to, money);
                                if (flag) {
                                    acc = atm.bank.login(id, password);
                                }
                            } catch (Exception ex) {
                                JOptionPane.showMessageDialog(null, ex.getMessage());
                                moneyTextField.setText("0.0");
                            }
                            //未添加网络编程 end*/

                            //===============添加网络编程  begin
                            //1.发送指令
                            atm.pw.println("transfer#"+id+"#"+password+"#"+toIdStr+"#"+money);
                            atm.pw.flush();

                            //4.读结果
                            try {
                                Object o = atm.ois.readObject();
                                if(o instanceof Account){
                                    acc = (Account) o;
                                }else if(o instanceof String){
                                    JOptionPane.showMessageDialog(this , o);
                                    moneyTextField.setText("0.0");
                                }
                            } catch (IOException ex) {
                                JOptionPane.showMessageDialog(this , "服务器已关闭");
                                System.exit(0);
                            } catch (ClassNotFoundException ex) {
                                throw new RuntimeException(ex);
                            }
                            //===============添加网络编程  end
                        } else {
                            JOptionPane.showMessageDialog(null, "转入账户不合法");
                        }
                        break;
                    case "修改透支额度":
                        password = JOptionPane.showInputDialog(null, "请输入您的密码：");
                        /*//未添加网络编程  begin
                        try {
                            acc = atm.bank.updateCeiling(id, password, money);
                        } catch (Exception ex) {
                            JOptionPane.showMessageDialog(null, ex.getMessage());
                            moneyTextField.setText("0.0");
                        }
                        break;
                        //未添加网络编程 end*/

                        //===============添加网络编程  begin
                        //1.发送指令
                        atm.pw.println("updateCeiling#"+id+"#"+password+"#"+money);
                        atm.pw.flush();

                        //4.读结果
                        try {
                            Object o = atm.ois.readObject();
                            if(o instanceof Account){
                                acc = (Account) o;
                            }else if(o instanceof String){
                                JOptionPane.showMessageDialog(this , o);
                                moneyTextField.setText("0.0");
                            }
                        } catch (IOException ex) {
                            JOptionPane.showMessageDialog(this , "服务器已关闭");
                            System.exit(0);
                        } catch (ClassNotFoundException ex) {
                            throw new RuntimeException(ex);
                        }
                        break;
                    //===============添加网络编程  end

                    case "贷款":
                       /* //未添加网络编程  begin
                        try {
                            acc = atm.bank.requestLoan(id, money);
                        } catch (Exception ex) {
                            JOptionPane.showMessageDialog(null, ex.getMessage());
                            moneyTextField.setText("0.0");
                        }
                        break;
                       //未添加网络编程 end*/

                        //===============添加网络编程  begin
                        //1.发送指令
                        atm.pw.println("requestLoan#"+id+"#"+money);
                        atm.pw.flush();

                        //4.读结果
                        try {
                            Object o = atm.ois.readObject();
                            if(o instanceof Account){
                                acc = (Account) o;
                            }else if(o instanceof String){
                                JOptionPane.showMessageDialog(this , o);
                                moneyTextField.setText("0.0");
                            }
                        } catch (IOException ex) {
                            JOptionPane.showMessageDialog(this , "服务器已关闭");
                            System.exit(0);
                        } catch (ClassNotFoundException ex) {
                            throw new RuntimeException(ex);
                        }
                        break;
                    //===============添加网络编程  end

                    case "还贷":
                        /*//未添加网络编程  begin
                        try {
                            acc = atm.bank.payLoan(id, money);
                        } catch (Exception ex) {
                            JOptionPane.showMessageDialog(null, ex.getMessage());
                            moneyTextField.setText("0.0");
                        }
                        break;
                        //未添加网络编程 end*/

                        //===============添加网络编程  begin
                        //1.发送指令
                        atm.pw.println("payLoan#"+id+"#"+money);
                        atm.pw.flush();

                        //4.读结果
                        try {
                            Object o = atm.ois.readObject();
                            if(o instanceof Account){
                                acc = (Account) o;
                            }else if(o instanceof String){
                                JOptionPane.showMessageDialog(this , o);
                                moneyTextField.setText("0.0");
                            }
                        } catch (IOException ex) {
                            JOptionPane.showMessageDialog(this , "服务器已关闭");
                            System.exit(0);
                        } catch (ClassNotFoundException ex) {
                            throw new RuntimeException(ex);
                        }
                        //===============添加网络编程  end
                        break;
                }

                // 刷新页面：初始化业务界面
                if (acc != null) {
                    atm.account = acc;
                    initBusiness();
                }
            } else {
                JOptionPane.showMessageDialog(null, "操作金额必须>0.0！");
            }
        } else {
            JOptionPane.showMessageDialog(null, "金额必须输入！");
        }
    }

    // 初始化后台监听线程，处理服务器推送的刷新请求
    public void startRefreshListener() {
        refreshThread = new Thread(() -> {
            try {
                while (!Thread.currentThread().isInterrupted()) {
                    Object obj = atm.ois.readObject();
                    if ("refresh".equals(obj)) {
                        // 收到刷新请求，重新登录获取最新数据
                        if (atm.account != null) {
                            atm.pw.println("refresh#" + atm.account.getId() + "#" + atm.account.getPassword());
                            atm.pw.flush();
                        }
                    } else if (obj instanceof Account) {
                        // 收到账户信息，更新界面
                        Account updatedAccount = (Account) obj;
                        SwingUtilities.invokeLater(() -> {
                            atm.account = updatedAccount;
                            initBusiness();
                        });
                    }
                }
            } catch (IOException | ClassNotFoundException e) {
                // 连接断开或其他异常，线程结束
                System.out.println("刷新监听线程结束: " + e.getMessage());
            }
        });
        refreshThread.setDaemon(true);
        refreshThread.start();
    }


    //点击返回，返回主界面
    private void back(ActionEvent e) {
        // TODO add your code here
        //获取当前LoginPanel的父窗口（ATMClient），的布局方式，即卡片式布局
        CardLayout cardLayout = (CardLayout)this.getParent().getLayout();
        //指定跳转至主界面
        cardLayout.show(this.getParent() , "mainPanel");
        clear();
    }
    //清空业务界面
    private void clear(){
        idText.setText("");
        nameLabelText.setText("");
        balanceLabelText.setText("");
        ceilingLabelText.setText("");
        loanLabelText.setText("");
        comboBox.setSelectedIndex(0);
        moneyTextField.setText(0.0+"");
    }
    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents  @formatter:off
        label1 = new JLabel();
        label2 = new JLabel();
        label3 = new JLabel();
        label4 = new JLabel();
        label5 = new JLabel();
        comboBox = new JComboBox<>();
        moneyTextField = new JTextField();
        submitButton = new JButton();
        backButton = new JButton();
        label6 = new JLabel();
        label7 = new JLabel();
        idLabelText = new JLabel();
        nameLabelText = new JLabel();
        balanceLabelText = new JLabel();
        ceilingLabelText = new JLabel();
        loanLabelText = new JLabel();
        label8 = new JLabel();
        idText = new JLabel();

        //======== this ========
        setLayout(null);

        //---- label1 ----
        label1.setText("\u8d26\u6237\uff1a");
        label1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 16));
        add(label1);
        label1.setBounds(80, 100, 90, 30);

        //---- label2 ----
        label2.setText("\u59d3\u540d\uff1a");
        label2.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 16));
        add(label2);
        label2.setBounds(80, 160, 90, 30);

        //---- label3 ----
        label3.setText("\u4f59\u989d\uff1a");
        label3.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 16));
        add(label3);
        label3.setBounds(80, 220, 90, 30);

        //---- label4 ----
        label4.setText("\u4fe1\u7528\u989d\u5ea6\uff1a");
        label4.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 16));
        add(label4);
        label4.setBounds(80, 280, 90, 30);

        //---- label5 ----
        label5.setText("\u8d37\u6b3e\u989d\u5ea6\uff1a");
        label5.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 16));
        add(label5);
        label5.setBounds(80, 340, 90, 30);

        //---- comboBox ----
        comboBox.setModel(new DefaultComboBoxModel<>(new String[] {
                "\u5b58\u6b3e",
                "\u53d6\u6b3e",
                "\u8f6c\u8d26",
                "\u4fee\u6539\u900f\u652f\u989d\u5ea6",
                "\u8d37\u6b3e",
                "\u8fd8\u8d37"
        }));
        add(comboBox);
        comboBox.setBounds(65, 415, 130, 35);

        //---- moneyTextField ----
        moneyTextField.setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR));
        moneyTextField.setText("0.0");
        add(moneyTextField);
        moneyTextField.setBounds(260, 415, 145, 35);

        //---- submitButton ----
        submitButton.setText("\u63d0\u4ea4");
        submitButton.addActionListener(e -> submit(e));
        add(submitButton);
        submitButton.setBounds(75, 505, 80, 30);

        //---- backButton ----
        backButton.setText("\u8fd4\u56de");
        backButton.addActionListener(e -> back(e));
        add(backButton);
        backButton.setBounds(305, 505, 80, 30);
        add(label6);
        label6.setBounds(145, 25, 105, label6.getPreferredSize().height);
        add(label7);
        label7.setBounds(150, 30, 100, label7.getPreferredSize().height);
        add(idLabelText);
        idLabelText.setBounds(115, 65, 185, idLabelText.getPreferredSize().height);

        //---- nameLabelText ----
        nameLabelText.setText(" ");
        add(nameLabelText);
        nameLabelText.setBounds(240, 160, 160, 35);

        //---- balanceLabelText ----
        balanceLabelText.setText(" ");
        add(balanceLabelText);
        balanceLabelText.setBounds(240, 220, 160, 35);

        //---- ceilingLabelText ----
        ceilingLabelText.setText(" ");
        add(ceilingLabelText);
        ceilingLabelText.setBounds(240, 280, 160, 35);

        //---- loanLabelText ----
        loanLabelText.setText(" ");
        add(loanLabelText);
        loanLabelText.setBounds(240, 340, 160, 35);

        //---- label8 ----
        label8.setText("\u4e1a\u52a1\u9875\u9762");
        label8.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 24));
        label8.setHorizontalAlignment(SwingConstants.CENTER);
        add(label8);
        label8.setBounds(195, 25, 100, 40);

        //---- idText ----
        idText.setText(" ");
        add(idText);
        idText.setBounds(240, 100, 160, 35);

        setPreferredSize(new Dimension(500, 650));
        // JFormDesigner - End of component initialization  //GEN-END:initComponents  @formatter:on
    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables  @formatter:off
    private JLabel label1;
    private JLabel label2;
    private JLabel label3;
    private JLabel label4;
    private JLabel label5;
    private JComboBox<String> comboBox;
    private JTextField moneyTextField;
    private JButton submitButton;
    private JButton backButton;
    private JLabel label6;
    private JLabel label7;
    private JLabel idLabelText;
    private JLabel nameLabelText;
    private JLabel balanceLabelText;
    private JLabel ceilingLabelText;
    private JLabel loanLabelText;
    private JLabel label8;
    private JLabel idText;
    // JFormDesigner - End of variables declaration  //GEN-END:variables  @formatter:on
}
